// const Core = require('@alicloud/pop-core');
const express = require('express')
const Router = express.Router()

const model = require('../model/model')

const User = model.getModel('user')


// var client = new Core({
//     accessKeyId: 'LTAI4FeMdcw7VprCd5LAyZjB',
//     accessKeySecret: '52efGG5Pqdwo4LMesiXNIUQnNmP9vN',
//     endpoint: 'https://dysmsapi.aliyuncs.com',
//     apiVersion: '2017-05-25'
// });

var params = {
    "RegionId": "cn-hangzhou"
}

var requestOption = {
    method: 'POST'
};

// client.request('SendSms', params, requestOption).then((result) => {
//     console.log(JSON.stringify(result));
// }, (ex) => {
//     console.log(ex);
// })


Router.post('/sendMsg', (req, res) => {
    const { phone } = req.body
    console.log('发送验证码的手机号： ' + phone)
    User.find({
        phone
    }, (err, dd) => {
        if (dd.length !== 0) {
            var whereStr = {
                phone
            }
            var updateStr = { $set: { "isSend": true } };
            User.updateOne(whereStr, updateStr, (e, d) => {
                if (err) throw err;
                return res.json({ code: 200, data: '发送短信成功' })
            })

        }
    })

})
module.exports = Router